package com.zzf.concurrent.example.design.pattern.future;

/**
 * @author GaoFeng2017
 * @date 2019/9/7 20:17
 */
public class AsyncFuture<T> implements Future<T> {

    private volatile boolean isDone;
    private volatile T result;

    @Override
    public synchronized T get() throws InterruptedException {
        while (!isDone) {
            this.wait();
        }
        return result;
    }

    public synchronized void done(T result) {
        this.isDone = true;
        this.result = result;
        this.notifyAll();
    }

}
